outfile.write("Info = {\n\n 'plug-in': 'Addons Menu Edit',")
outfile.write("\n\n 'desc': 'This file stores the Addons Main menu, Category sub-menu items. It is created by the plugins map1addonsamendmenu.py file.',")
outfile.write("\n\n 'date': 'June 7 2003',")
outfile.write("\n\n 'author': 'cdunde, Decker and others',")
f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
except (IOError):
# *********** If first time used then it runs this script **********
CreateMenuItems(self)
quarkx.msgbox("The menu item has been added and stored\nin the newly created Addons Menu Edit file:\n"+("\r\n" + quarkx.exepath + "plugins\map1AddonsMenuEdit.py")+"\n\nYou need to restart QuArK to undate the menu", MT_INFORMATION, MB_OK)
return None
# ******** If map1AddonsMenuEdit.py file exists but no items ********
NbrOfBoxes = 0
while 1:
line = f.readline()
if line == '': # completely empty line means end-of-file
break
words = line.split('\r\n')
for word in words:
if word == "# ------------ Delete This Item ------------\n":
NbrOfBoxes = NbrOfBoxes + 1
if NbrOfBoxes == 0:
f.close()
CreateMenuItems(self)
quarkx.msgbox("The item has been added to the Addons Menu Edit file: "+("\r\n" + quarkx.exepath + "plugins\map1AddonsMenuEdit.py")+"\n\nYou need to restart QuArK to undate the menu", MT_INFORMATION, MB_OK)
return
# ********** If map1AddonsMenuEdit.py file already exists with items **********
# ********* This part sets parameters and starts copying the old file data *******
NewItem = ""
itemadded = 0
flag = 0
if catagory == "1":
catagory = "ShapesMenu"
if catagory == "2":
catagory = "TerrainMenu"
if catagory == "3":
catagory = "OtherMenu"
mapfile = self.src["mapfile"]
objfile = mapfile.replace("\\", "/")
f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
while 1:
line = f.readline()
if line == '': # completely empty line means end-of-file
break
words = line.split('\r\n')
for word in words:
if word == "plugins.map1addonsmenu." + catagory + ".items.append(qmenu.sep)\n":
itemadded = 1
flag = 1
if itemadded == 1:
me = 1
else:
if catagory == "ShapesMenu":
if word == "plugins.map1addonsmenu.TerrainMenu.items.append(qmenu.sep)\n":
holdword = word
NewItem = "ItemAdded"
itemadded = 1
flag = 1
word = "#===========================================\n"
else:
if word == "plugins.map1addonsmenu.OtherMenu.items.append(qmenu.sep)\n":
holdword = word
NewItem = "ItemAdded"
itemadded = 1
flag = 1
word = "#===========================================\n"
if itemadded == 1:
me = 1
else:
if catagory == "TerrainMenu":
if word == "plugins.map1addonsmenu.OtherMenu.items.append(qmenu.sep)\n":
holdword = word
NewItem = "ItemAdded"
itemadded = 1
flag = 1
word = "#===========================================\n"
else:
if catagory == "OtherMenu":
if word == "# End Of File\n":
holdword = word
NewItem = "ItemAdded"
itemadded = 1
flag = 1
word = "#===========================================\n"
if flag == 1:
if word == "#===========================================\n":
# ********* This part adds the new data then finishes copying the old file data *******
text = text + ("plugins.map1addonsmenu."+catagory+".items.append(qmenu.sep)\n\n")
text = text + ("# ------------ Delete This Item ------------\n\n")
text = text + ("# Menu Catagory: "+catagory+"\n")
text = text + ("# Menu Title: Run "+name+"\n\n")
text = text + ("def Run_"+name+"(self):\n pass\n cmdline = '"+cmdline+"'\n currentdir = '"+currentdir+"'\n quarkx.runprogram(cmdline, currentdir)\n\n")
text = text + ("plugins.map1addonsmenu."+catagory+".items.append(quarkpy.qmenu.item('Run "+name+"', Run_"+name+",'|This programs location is:\\n\\n"+proglocate+"'))\n\n")
text = text + ("# ------------ End Item Cutting ------------\n\n")
text = text + ("# ------------ Delete This Item ------------\n\n")
text = text + ("# Menu Catagory: "+catagory+"\n")
text = text + ("# Menu Title: Import "+name+" map\n\n")
text = text + ("def Load_"+name+"_Map(editor):\n pass\n editor = mapeditor()\n info = quarkx.openfileobj('"+objfile+"')\n mygroup = quarkx.newobj('group:g')\n")
text = text + (" mygroup.copyalldata(info.subitem(0))\n quarkpy.mapbtns.dropitemsnow(editor, [mygroup], 'draw map')\n\n")
text = text + ("plugins.map1addonsmenu."+catagory+".items.append(quarkpy.qmenu.item('Import "+name+" map', Load_"+name+"_Map,'|This maps location is:\\n\\n"+objfile+"'))\n\n")
text = text + ("# ------------ End Item Cutting ------------\n\n")
flag = 0
if NewItem == "ItemAdded":
text = text + ("#===========================================\n\n")
quarkx.msgbox("The item has been added to the Addons Menu Edit file: "+("\r\n" + quarkx.exepath + "plugins\map1AddonsMenuEdit.py")+"\n\nYou need to restart QuArK to undate the menu", MT_INFORMATION, MB_OK)
editor=mapeditor()
if editor is None: return
AddonsDlg(quarkx.clickform,editor,action)
# ****************** END OF ADD TO MENU SECTION ******************
# ****************** Remove Menu Items Function ******************
# ******************* Delete Menu Items Dialog ******************
class DeleteDlg(quarkpy.qmacro.dialogbox):
def BuildCheckboxesForDialog(self, array):
# creates the menu array data from the map1AddonsMenuEdit.py file
# *************************** start of array ********************
cat = '0'
shapes = '0'
terrain = '0'
other = '0'
text = ''
shapestext = ''
terraintext = ''
othertext = ''
try:
f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
except (IOError):
quarkx.msgbox("No custom items have been\nadded to the Category menus\n\n Nothing To Do", MT_INFORMATION, MB_OK)
return None
while 1:
line = f.readline()
if line == '': # completely empty line means end-of-file
break
words = line.split('\n')
words = line.split(' ')
for word in words:
if word == 'Catagory:':
catagory = (line[2:+16])
if cat == '0':
cat = '1'
menuname = (line[17:+62])
if menuname == 'ShapesMenu\012':
if shapes == '0':
shapestext = menuname
shapes = '1'
if menuname == 'TerrainMenu\012':
if terrain == '0':
terraintext = menuname
terrain = '1'
if menuname == 'OtherMenu\012':
if other == '0':
othertext = menuname
other = '1'
else:
menuname = (line[17:+62])
if menuname == 'ShapesMenu\012':
if shapes == '0':
shapestext = menuname
shapes = '1'
if menuname == 'TerrainMenu\012':
if terrain == '0':
terraintext = menuname
terrain = '1'
if menuname == 'OtherMenu\012':
if other == '0':
othertext = menuname
other = '1'
if word == 'Title:':
itemname = (line[14:+62])
if menuname == 'ShapesMenu\012':
shapestext = shapestext + itemname
if menuname == 'TerrainMenu\012':
terraintext = terraintext + itemname
if menuname == 'OtherMenu\012':
othertext = othertext + itemname
data = shapestext + terraintext + othertext
f.close()
# ************** MAKE DIALOG *******************
contentstemplate = """
Contents:={Txt="<text>" Typ="S" Hint="Check to remove items below"} """
septemplate = """sep: = { Typ="S" Txt="" }"""
checkboxtemplate = """
cb<number>: =
{ Typ="X" Cap="<caption>" Txt="<text>" } """
dlgdef = """
{
Style="9"
Caption="Delete Checked Items from Menu"
<checkboxes>
sep: = { Typ="S" Txt="" }
close:py = {Txt="" }
cancel:py = {Txt="" }
} """
Contents = ""
labelArray = ""
array = data
checkboxes_string = ""
num = 0
words = array.split('\n')
for item in words:
if item == '': # completely empty line means end-of-file
# ********* End of Remove Double Lines function *********
quarkx.msgbox("The checked menu items have been removed\nfrom the recreated Addons Menu Edit file:\n"+("\r\n" + quarkx.exepath + "plugins\map1AddonsMenuEdit.py")+"\n\nYou need to restart QuArK to undate the menu", MT_INFORMATION, MB_OK)
editor=mapeditor()
if editor is None: return
DeleteDlg(quarkx.clickform,editor,action)
# **************** END OF REMOVE FROM MENU SECTION ****************
# ********* This creates the Addons Amend menu items ***************
X0 = quarkpy.qmenu.item("Add menu item", AddItemClick, "|Add menu item:\n\nThis will add a 3rd party program to the menu.\n\nUsing the 'Add Item Dialog' window, select a category to place your menu items under and then find the program you want to add by using the 'select program' file browser '...' button to the right of the input box.\n\nYou can either leave the output/input default file at its current setting and point the programs output to it or use the 'File Browser' button ... to select another map file and location to use.\n\nOnce the program items are added, you will be given a notice as such and to restart QuArk to complete the process of adding the items to your menu.\n\nYou can add as many items to your menu as you like before restarting QuArk.\n\nEach program added will have two items (with the programs name) and a separation line to isolate them for easy recognition, as well as F1 popup windows to remind you where the program and import files are located on your hard drive.\n\nThe first item starts the program. Once you have exported its finished product to the default map file, then use the second item to import the map file into the QuArk editor. The entire product will be added to the map you are currently working on as a separate group item.\n\nAlthough the 'worldspawn' entity will NOT be imported, other entities can be and may require you to delete them, like another 'info_player_start' for example.\n\nBecause these ARE 3rd party programs, QuArK does not provide any documentation on their use and makes no warranty for them.|intro.mapeditor.menu.html#addonsmenu")
X1 = quarkpy.qmenu.item("Remove menu items", RemoveItemClick, "|Remove menu items:\n\nUse this function to remove the desired custom menu items that have been added.|intro.mapeditor.menu.html#addonsmenu")
AmendMenuCmds = [quarkpy.qmenu.popup("&Add \ Delete menu items", [], ViewAmendMenu1click, "|Add \ Delete menu items:\n\nThese functions allow you to add and delete 3rd party programs to this menu, that save or export their output to a map file which can then be imported to the QuArK editor and used in the file you are editing.\n\nYou can use any .map file that the program outputs to, at any location, or a default map file as your input file.\n\nThe default import file should be created and saved to YourGame\\tmpQuArk\maps folder and named '1SaveImport.map' .\n\nIf this file is damaged or lost it can be recreated by simply making a basic map file in QuArk (with world_spawn ONLY) and saved with the default file name above.", "intro.mapeditor.menu.html#addonsmenu")]
# ----------- REVISION HISTORY ------------
#
#$Log: map1addonsamendmenu.py,v $
#Revision 1.2 2003/12/18 21:51:46 peter-b
#Removed reliance on external string library from Python scripts (second try ;-)